package com.itany.controller;

import com.itany.book.service.ManagerUserService;
import com.itany.exception.RequestParamException;
import com.itany.exception.UserNotExistException;
import com.itany.pojo.ManagerUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * Auther:ws@itany.com
 * Date:20-10-9 下午1:48
 * Version:1.0
 * Description:
 */
@Controller
@RequestMapping("/managerUser")
public class ManagerUserController {
    @Autowired
    private ManagerUserService managerUserService;

    @ResponseBody
    @RequestMapping("/login")
    public ModelAndView login(String username, String password, HttpSession session){
        ModelAndView mav = new ModelAndView();
        try {
            ManagerUser user = managerUserService.login(username, password);
            session.setAttribute("User",user);
            mav.setViewName("redirect:/manager/showMain");
        } catch (RequestParamException e) {
            mav.setViewName("login");
            e.printStackTrace();
        } catch (UserNotExistException e) {
            mav.setViewName("login");
            e.printStackTrace();
        }
        return mav;
    }
}
